from matchmenu import MatchMenu
from matchteam import MatchTeam


class Match(object):
    
    def __init__(self, team1, team2):
        self.match_team1 = MatchTeam(team1, True)
        self.match_team2 = MatchTeam(team2, False)
        self.score1 = -1
        self.score2 = -1
        self.played = False
    
    def __str__(self):
        if self.played:
            return '%s %dx%d %s' % (self.match_team1.team.name, self.score1,
                                    self.score2, self.match_team2.team.name)
        else:
            return '%s x %s' % (self.match_team1.team.name,
                                self.match_team2.team.name)
    
    def set_result(self, score1, score2):
        self.score1 = score1
        self.score2 = score2
        self.played = True

    def play(self):
        match_menu = MatchMenu(self)
        match_menu.sync_open()
        print 'Match.play -> %s' % self
